﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;

public partial class Register : System.Web.UI.Page
{
    Utilities utilities = new Utilities();
    string defaultRoom;

    protected AlertMessage.MessageData alertMessageData = new AlertMessage.MessageData();
    protected string pinCode = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        defaultRoom = utilities.DefaultRoomRedirectExists(Request.QueryString["def"]);

        // Message-check
        alertMessageData = AlertMessage.OutputAlertMessage(Request.QueryString["m"]);

        if (!string.IsNullOrEmpty(Request.QueryString["yourPin"]))
        {
            alertMessageData.Message += "<br /><strong>Din PIN-kod är " + Request.QueryString["yourPin"] + "!</strong><br />Spara denna, den behövs för att kunna uppdatera och ta bort bokningar";
        }

        if (IsPostBack)
        {
            string name = Server.HtmlEncode(Request.Form["tBoxName"]);
            string email = Server.HtmlEncode(Request.Form["tBoxEmail"]);
            string emailVerify = Server.HtmlEncode(Request.Form["tBoxEmailVerify"]);

            Response.Redirect(utilities.AddUser(name, email, emailVerify));   
        }

        CheckHomeDestination();
    }

    // Skickar tillbaka besökaren efter 5 minuter
    protected void CheckHomeDestination()
    {
        if (!string.IsNullOrEmpty(defaultRoom))
        {
            Response.AddHeader("REFRESH", "300;URL=?d=" + DateTime.Today.ToString("yyyy-MM-dd") + "&r=" + defaultRoom + "&def=" + defaultRoom);
        }
    }
}